package week12.config;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



/**
 * @author lfy
 */
@Configuration
public class TopicExchangeRabbitMQConfig {

    public static final String topicExchangeName = "topicExchange1";

    private static final String queue1BindingKey1 = "*";
    private static final String queue1BindingKey2 = "#";

    // 声明主题交换机
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(topicExchangeName);
    }

    // 声明消息队列
    @Bean
    public Queue messageQueue1() {
        return new Queue("queue1");
    }


    // 向主题交换机上绑定队列
    @Bean
    Binding bindingQueue1Exchange1(Queue messageQueue1, TopicExchange topicExchange) {
        return BindingBuilder.bind(messageQueue1)
                .to(topicExchange)
                .with(queue1BindingKey1);
    }

    @Bean
    Binding bindingQueue1Exchange2(Queue messageQueue1, TopicExchange topicExchange) {
        return BindingBuilder.bind(messageQueue1)
                .to(topicExchange)
                .with(queue1BindingKey2);
    }

}